<template>
  <div class="login-panel">
    <h1 class="login-panel-title">PINK</h1>
    <el-tabs type="border-card" class="demo-tabs" stretch v-model="tabsModel">
      <el-tab-pane name="account">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon><User /></el-icon>
            <span>账号登陆</span>
          </span>
        </template>
        <loginAccount ref="accountRef"></loginAccount>
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon><Iphone /></el-icon>
            <span>手机登录</span>
          </span>
        </template>
        <loginPhone ref="phoneRef"></loginPhone>
      </el-tab-pane>
    </el-tabs>
    <div class="login-panel-control">
      <el-checkbox v-model="rememberPassword" label="记住密码" />
      <el-link type="primary" href="/#/main">忘记密码</el-link>
    </div>
    <div class="login-panel-login">
      <el-button type="primary" @click="handleLoginClick">立即登录</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import loginAccount from './login-account.vue'
import loginPhone from './login-phone.vue'
import { ref } from 'vue'

const rememberPassword = ref(true)
const tabsModel = ref<string>('account')

const accountRef = ref<InstanceType<typeof loginAccount>>()
const phoneRef = ref<InstanceType<typeof loginPhone>>()

const handleLoginClick = () => {
  if ( tabsModel.value == 'account') {
    // 账号密码登录
    accountRef.value?.loginAction(rememberPassword.value)
  }else if ( tabsModel.value == 'phone' ){
    // 手机号登录
    console.log(phoneRef.value);
  }
}
</script>

<style lang="scss" scoped>
.login-panel {
  width: 320px;
  margin-bottom: 120px;
  &-title {
    text-align: center;
  }
  &-control {
    margin-top: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  &-login {
    width: 100%;
    margin-top: 8px;
    height: 100%;
    :deep(.el-button) {
      width: 100%;
    }
  }
}
</style>
